package cn.yh.nft.turbo.collection.domain.entity;

import cn.yh.nft.turbo.api.collection.constant.CollectionEvent;
import cn.yh.nft.turbo.api.collection.constant.CollectionStateEnum;
import cn.yh.nft.turbo.api.goods.constant.GoodsEvent;
import cn.yh.nft.turbo.datasource.domain.entity.BaseEntity;
import lombok.Getter;
import lombok.Setter;
import org.apache.ibatis.executor.BaseExecutor;

import java.math.BigDecimal;
import java.util.Date;

/**
 * <p>
 *     藏品流水信息
 * </p>
 * @ClassName: CollectionStream
 * @Author: 草莓爱上啵啵
 */
@Getter
@Setter
public class CollectionStream extends BaseEntity {

    /**
     * 流水类型
     */
    private GoodsEvent streamType;

    /**
     * 藏品id
     */
    private Long collectionId;

    /**
     * 藏品名称
     */
    private String name;

    /**
     * 藏品封面
     */
    private String cover;

    /**
     * 藏品类目id
     */
    private String classId;

    /**
     * 价格
     */
    private BigDecimal price;

    /**
     * 藏品数量
     */
    private Integer quantity;

    /**
     * 藏品详情
     */
    private String detail;

    /**
     * 可售库存
     */
    private Long saleableInventory;

    /**
     * 已占库存
     */
    private Long occupiedInventory;

    /**
     * 状态
     */
    private CollectionStateEnum state;

    /**
     * 藏品创建时间
     */
    private Date createTime;

    /**
     * 藏品发售时间
     */
    private Date saleTime;

    /**
     * 藏品上链时间
     */
    private Date syncChainTime;

    /**
     * 幂等号
     */
    private String identifier;

    /**
     * 初始化了一个藏品流水信息
     * @param collection
     * @param identifier
     * @param streamType
     */
    public CollectionStream(Collection collection, String identifier, GoodsEvent streamType){
        //藏品id
        this.collectionId = collection.getId();
        //=藏品名字
        this.name = collection.getName();
        //藏品封面
        this.cover = collection.getCover();
        //藏品类目Id
        this.classId = collection.getClassId();
        //藏品价格
        this.price = collection.getPrice();
        //藏品数量
        this.quantity = collection.getQuantity();
        //藏品详情
        this.detail = collection.getDetail();
        //可售库存
        this.saleableInventory = collection.getSaleableInventory();
        //已占库存
        this.occupiedInventory = collection.getOccupiedInventory();
        //状态
        this.state = collection.getState();
        //创建时间
        this.createTime = collection.getCreateTime();
        //柳树类型
        this.streamType = streamType;
        //发售时间
        this.saleTime = collection.getSaleTime();
        //上链时间
        this.syncChainTime = collection.getSyncChainTime();
        //幂等号
        this.identifier = identifier;
        //乐观锁版本号
        super.setLockVersion(collection.getLockVersion());
        //是否删除
        super.setDeleted(collection.getDeleted());
    }

}
